How to count characters in a string?

Hi Guys,

i've got a script that manages some access rights and now i'm facing a problem.
My inputs are pathes like "/ProjectA/Folder1/Folder2/MolduleI" and i want to split them in the path of every single item, it should look like this:
"/ProjectA"
"/ProjectA/Folder1"
"/ProjectA/Folder1/Folder2"
"/ProjectA/Folder1/Folder2/MolduleI"

My first idea was to count the slashes in the string, but i dont know how, can you help me?

Regards,
Manuel
ManuelFelger - Fri Apr 17 04:03:10 EDT 2009

Re: How to count characters in a string?
Tony_Goodman - Fri Apr 17 05:38:18 EDT 2009

You could do this by looping through the string and looking for the slashes, but if you are dealing with DOORS paths then the following might be more reliable/efficient:
 

string sPath = "/AMG/Red/Green/Blue/Black"
 
print(sPath "\n")
 
ModName_ m = module(sPath)
 
Folder f = getParentFolder(m)
 
while (!null f)
{
    print(fullName(f) "\n")
 
        f = getParentFolder(f)
}

Re: How to count characters in a string?
ManuelFelger - Fri Apr 17 05:55:46 EDT 2009

Tony_Goodman - Fri Apr 17 05:38:18 EDT 2009

You could do this by looping through the string and looking for the slashes, but if you are dealing with DOORS paths then the following might be more reliable/efficient:
 

string sPath = "/AMG/Red/Green/Blue/Black"
 
print(sPath "\n")
 
ModName_ m = module(sPath)
 
Folder f = getParentFolder(m)
 
while (!null f)
{
    print(fullName(f) "\n")
 
        f = getParentFolder(f)
}

Thank you Tony, it works!

Regards,
Manuel

Re: How to count characters in a string?
Tony_Goodman - Fri Apr 17 06:12:50 EDT 2009

ManuelFelger - Fri Apr 17 05:55:46 EDT 2009
Thank you Tony, it works!

Regards,
Manuel

Of course it works ;-)

Here's how to do with strings:
 

string sPath = "/AMG/Red/Green/Blue/Black"
 
print(sPath "\n")
 
int i = 0
 
for (i = length(sPath) - 1; i > 0; i--)
{
    if (sPath[i] == '/')
        {
                print(sPath[0:i-1] "\n")
        }
}